package com.hfdg.dictionary.ctrl;

import com.hfdg.prototype.base.model.AjaxResult;
import com.hfdg.dictionary.entity.Dictionary;
import com.hfdg.dictionary.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.Model;

/**
 * @ClassName DictionaryCtrl
 * @Description TODO
 * @Author yuelh
 * @Date 2020/01/31 02:26:15
 * @Version 1.0
 * @Company 会飞的锅工作室
 **/
@Controller
@RequestMapping("/dictionary")
public class DictionaryCtrl {
    @Autowired
    DictionaryService dictionaryService;
     /**
     * @Author: yuelh
     * @Description:  TODO 保存数据
     * @Date:  2020/01/31 14:26:15
     * @Param: dictionary
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/save")
    @ResponseBody
    public AjaxResult save (Dictionary dictionary){
        if(null!=dictionary.getUid()){
            dictionaryService.update(dictionary);
        }else{
           dictionaryService.insert(dictionary);
        }
        return AjaxResult.success();
    }
     /**
     * @Author: yuelh
     * @Description:  TODO 根据UID删除数据
     * @Date:  2020/01/31 14:26:15
     * @Param: uid 要删除的数据条目的uid
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String uid){
            dictionaryService.delete(uid);
            return AjaxResult.success();
    }
    /**
         * @Author: yuelh
         * @Description:  TODO 根据UID删除数据
         * @Date:  2020/01/31 14:26:15
         * @Param: uid 要删除的数据条目的uid
         * @return: com.hfdg.base.domains.AjaxResult
         **/
        @RequestMapping("/batchRemove")
        @ResponseBody
        public AjaxResult batchRemove(@RequestParam("uids[]") String[] uids){
                 dictionaryService.batchDelete(uids);
                return AjaxResult.success();
        }
    /**
     * @Author: yuelh
     * @Description:  TODO 数据列表
     * @Date:  2020/01/31 14:26:15
     * @Param: dictionary 查询条件
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/list")
    @ResponseBody
    public  AjaxResult list(Dictionary dictionary){
        return AjaxResult.success(dictionaryService.list(dictionary));
    }
    /**
     * @Author: yuelh
     * @Description:  TODO 数据列表,分页
     * @Date:  2020/01/31 14:26:15
     * @Param: offset 数据偏移值，limit 单页最大记录数，orderBy 排序字段 ，dictionary 查询条件
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/getPagingData")
    @ResponseBody
    public AjaxResult getPagingData(Integer offset,Integer limit,String orderBy,Dictionary dictionary){
        return  AjaxResult.success(dictionaryService.getPagingData(offset,limit,orderBy,dictionary));
    }

     /**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至表单页面
     * @Date:  2020/01/31 14:26:15
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toCreateView")
    public String toForm(HttpServletRequest request, HttpServletResponse response,Model model){
        return "commons/"+"authority"+"/"+"dictionaryCreateView";
    }

/**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至编辑页面
     * @Date:  2020/01/31 14:26:15
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toEditView")
    public String toEditView(HttpServletRequest request, HttpServletResponse response,String uid,Model model){
            Dictionary dictionary= dictionaryService.get(uid);
            model.addAttribute("formData",dictionary);
            return "commons/"+"authority"+"/"+"dictionaryEditView";
        }


/**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至对应列表页面
     * @Date:  2020/01/31 14:26:15
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toListView")
    public String toListView(HttpServletRequest request, HttpServletResponse response){
        return "commons/"+"authority"+"/"+"dictionaryListView";
    }

    /**
     * @Author: yuelh
     * @Description:  TODO 页面跳转
     * @Date:  2020/01/31 14:26:15
     * @Param: page  要跳转的页面
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/view/{page}")
    public String view(HttpServletRequest request, HttpServletResponse response, @PathVariable("page") String page){
        return "commons/"+"authority"+"/"+page;
    }


}
